<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi, Teow Jit Huan
 *
 */

class CommitteetodosController extends AppController {

    /**
     * Define $name
     *
     */
    var $name = 'Committeetodos';
    /**
     * Define $helpers
     *
     */
    var $helpers = array('Html', 'Form');
    /**
     * Define $priorities
     *
     */
    var $priorities = array('1'=>'Immediate', '2'=>'Urgent', '3'=>'High', '4'=>'Normal', '5'=>'Low', '6'=>'None');


    /**
     * Describe index
     *
     * @param $committee
     * @return null
     */
    function index($committee) {
        $this->Committeetodo->Committee->unbindModel(array('hasMany'=>array('Announcement','Item','Group','Meeting','Decision','Todo','Userstatus','Groupstatus','Workflow','Wfmodel'),'hasAndBelongsToMany'=>array('User','Membership')),false);
        
        $this->set('dcommittee',$this->dcommittee);
        $this->Committeetodo->recursive = 0;
        $condition['committee_id']=$this->dcommittee['Committee']['id'];
        if(!empty($this->data['Search']['name'])){
            $condition['Committeetodo.name like']='%'.$this->data['Search']['name'].'%';
        }
        if(!empty($this->data['Search']['priority'])){
            $condition['Committeetodo.priority']=$this->data['Search']['priority'];
        }
        $committeestodo=$this->paginate('Committeetodo',$condition);
        $this->set('committeesTodos', $committeestodo);
        
        
        $this->set('committee',$committee);
        $priorities = array('1'=>__('Immediate', true), '2'=>__('Urgent', true), '3'=>__('High', true), '4'=>__('Normal', true), '5'=>__('Low', true), '6'=>__('None', true));
        $this->set(compact('priorities'));         

    }


        /*$this->Committeetodo->recursive = 0;
             if(isset($this->params['named']['committee_id'])){
            $this->set('committeesTodos', $this->paginate('Committeetodo',array('Committeetodo.committee_id'=>$this->params['named']['committee_id'])));
            $this->set('curcommittee',$this->params['named']['committee_id']);
        }
        else{
            $this->set('committeesTodos', $this->paginate());
        }
        $this->set('allow_add_committeesTodos',true);
        }*/



    /**
     * Describe view
     *
     * @param $committee
     * @param $id
     * @return null
     */
    function view($committee,$id = null) {
        $this->Committeetodo->Committee->unbindModel(array('hasMany'=>array('Announcement','Item','Group','Meeting','Decision','Todo','Userstatus','Groupstatus','Workflow','Wfmodel'),'hasAndBelongsToMany'=>array('User','Membership')),false);
        
        $this->set('dcommittee',$this->dcommittee);
        if (!$id) {
            $this->Session->setFlash(__('Invalid Committeetodo.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('committeesTodo', $this->Committeetodo->read(null, $id));
        $this->set('priorities',$this->priorities); 
    }

    /**
     * Describe add
     *
     * @param $committee
     * @return null
     */
    function add($committee) {
        $this->Committeetodo->Committee->unbindModel(array('hasMany'=>array('Announcement','Item','Group','Meeting','Decision','Todo','Userstatus','Groupstatus','Workflow','Wfmodel'),'hasAndBelongsToMany'=>array('User','Membership')),false);
        
        $this->set('dcommittee',$this->dcommittee);
        if (!empty($this->data)) {
            $this->Committeetodo->create();
            if ($this->Committeetodo->save($this->data)) {
                $this->Session->setFlash(__('The To-do has been saved', true));
                $this->redirect(array('committee'=>$committee,'action'=>'index'));
            } else {
                $this->Session->setFlash(__('The To-do could not be saved. Please, try again.', true));
            }
        }
        $committees = $this->Committeetodo->Committee->find('list');
        $priorities = array('1'=>__('Immediate', true), '2'=>__('Urgent', true), '3'=>__('High', true), '4'=>__('Normal', true), '5'=>__('Low', true), '6'=>__('None', true));
        $this->set(compact('committees','priorities'));
        if(isset($this->params['named']['committee_id'])){
            $this->set('curcommittee',$this->params['named']['committee_id']);
        }
        $this->set('users', $this->Committeetodo->User->getUsersPerCommitteeList($this->dcommittee['Committee']['id']));
        $this->set('returnpage',$this->referer(null,true));
    }

    /**
     * Describe edit
     *
     * @param $committee
     * @param $id
     * @return null
     */
    function edit($committee=null,$id = null) {
        $this->Committeetodo->Committee->unbindModel(array('hasMany'=>array('Announcement','Item','Group','Meeting','Decision','Todo','Userstatus','Groupstatus','Workflow','Wfmodel'),'hasAndBelongsToMany'=>array('User','Membership')),false);
        
        $this->set('dcommittee',$this->dcommittee);
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Committeetodo', true));
            $this->redirect(array('committee'=>$committee,'action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Committeetodo->save($this->data)) {
                $this->Session->setFlash(__('The Committeetodo has been saved', true));
                $this->redirect(array('committee'=>$committee,'action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Committeetodo could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Committeetodo->read(null, $id);
            $this->set('committeesTodo', $this->data);
        }
        $committees = $this->Committeetodo->Committee->find('list');
        $priorities = array('1'=>__('Immediate', true), '2'=>__('Urgent', true), '3'=>__('High', true), '4'=>__('Normal', true), '5'=>__('Low', true), '6'=>__('None', true));
        $this->set(compact('committees','priorities'));
        $this->set('users', $this->Committeetodo->User->getUsersPerCommitteeList($this->dcommittee['Committee']['id']));
    }

    /**
     * Describe delete
     *
     * @param $committee
     * @param $id
     * @return null
     */
    function delete($committee,$id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Committeetodo', true));
            $this->redirect(array('committee'=>$committee,'action'=>'index'));
        }
        $this->Committeetodo->delete($id);
        $this->Session->setFlash(__('Committeetodo deleted', true));
        $this->redirect(array('committee'=>$committee,'action'=>'index'));
    }

}
?>
